package com.example.demos.service.Impl;

import com.example.demos.common.MyBatisUtils;
import com.example.demos.dao.AdminUserDao;
import com.example.demos.dao.UserDao;
import com.example.demos.model.AdminUser;
import com.example.demos.model.User;
import com.example.demos.service.AdminUserService;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

@Service
public class AdminUserServiceImpl implements AdminUserService {


    @Override
    public List<Object> getList() {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        AdminUserDao adminUserDao =  sqlSession.getMapper(AdminUserDao.class);
//        AdminUser adminUser = adminUserDao.selectByList();
        List<Object> adminUserList = adminUserDao.selectByList();
        sqlSession.close();
        return adminUserList;
    }

    @Override
    public AdminUser getUser(String username) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        AdminUserDao adminUserDao =  sqlSession.getMapper(AdminUserDao.class);
        AdminUser adminUser = adminUserDao.selectByMobile(username);
        sqlSession.close();
        return adminUser;
    }

    @Override
    public AdminUser getUserId(Integer id) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        AdminUserDao adminUserDao =  sqlSession.getMapper(AdminUserDao.class);
        AdminUser adminUser = adminUserDao.selectById(id);
        sqlSession.close();
        return adminUser;
    }

    @Override
    public boolean login(String username, String password) {
        SqlSession sqlSession = MyBatisUtils.getSqlSession();
        AdminUserDao adminUserDao =  sqlSession.getMapper(AdminUserDao.class);
        boolean adminUser = adminUserDao.selectByPassword(username,password);
        sqlSession.close();
        return adminUser;
    }
}
